package com.backedserver.controller.judicialcheck;

import com.alibaba.excel.EasyExcelFactory;
import com.common.base.BindCreateBy;
import com.common.base.BindUpdateBy;
import com.common.excel.ExcelUtil;
import com.common.global.BizException;
import com.common.global.BizServiceEnum;
import com.common.requestvo.judicialcheck.JudicialCheckFillCountReqVo;
import com.common.requestvo.judicialcheck.JudicialCheckReqVo;
import com.common.requestvo.judicialcheck.JudicialTargetTypeSumCheckRankReqVo;
import com.common.requestvo.judicialcheck.JudicialTargetTypeSumCheckReqVo;
import com.common.service.judicialcheck.JudicialCheckService;
import com.common.service.judicialcheck.JudicialTargetTypeSumCheckService;
import com.common.utils.JwtTokenUtils;
import com.common.utils.PageUtil;
import com.common.utils.ResultVoUtil;
import com.common.vo.PageVo;
import com.common.vo.ResultVo;
import com.common.vo.judicialcheck.JudicialCheckVo;
import com.common.vo.judicialcheck.JudicialDepartmentSumScoreCheckVo;
import com.common.vo.judicialcheck.JudicialTargetTypeSumCheckVo;
import com.common.vo.judicialpersonal.JudicialPersonalVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 指标导入Controller
 *
 * @author johnny
 * @create 2021-05-15 8:17 上午
 **/

@Api(tags = "决策分析模块")
@RestController
@RequestMapping("/judicial_target_type_sum_check")
@Slf4j
public class JudicialTargetTypeSumCheckController {


    private final JudicialTargetTypeSumCheckService judicialTargetTypeSumCheckService;

    public JudicialTargetTypeSumCheckController(JudicialTargetTypeSumCheckService judicialTargetTypeSumCheckService) {
        this.judicialTargetTypeSumCheckService = judicialTargetTypeSumCheckService;
    }

    @ModelAttribute
    public JudicialTargetTypeSumCheckReqVo createByBind(JudicialTargetTypeSumCheckReqVo judicialTargetTypeSumCheckReqVo, HttpServletRequest request) {
        judicialTargetTypeSumCheckReqVo.setCreateBy(JwtTokenUtils.getUserNameFromReq(request));
        return judicialTargetTypeSumCheckReqVo;
    }

    @GetMapping("/listByCondition")
    @ApiOperation(value = "根据条件查询 个人类型考核总计信息 (分页)")
    public ResultVo listByCondition(JudicialTargetTypeSumCheckReqVo judicialTargetTypeSumCheckReqVo,
                                    PageVo pageVo) {
        pageVo.setPageNumber(pageVo.getPageNumber() - 1);
        Page<JudicialTargetTypeSumCheckVo> page = judicialTargetTypeSumCheckService.listByCondition(judicialTargetTypeSumCheckReqVo, PageUtil.initPage(pageVo));
        return ResultVoUtil.success(page);
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增 个人类型考核总计信息")
    @BindCreateBy
    public ResultVo add(@RequestBody JudicialTargetTypeSumCheckReqVo judicialTargetTypeSumCheckReqVo) {
        judicialTargetTypeSumCheckService.add(judicialTargetTypeSumCheckReqVo);
        return ResultVoUtil.success();
    }

    @PostMapping("/edit")
    @ApiOperation(value = "修改 个人类型考核总计信息")
    @BindUpdateBy
    public ResultVo edit(@RequestBody JudicialTargetTypeSumCheckReqVo judicialTargetTypeSumCheckReqVo) {
        judicialTargetTypeSumCheckService.edit(judicialTargetTypeSumCheckReqVo);
        return ResultVoUtil.success();
    }

    @GetMapping("/delete/{id}")
    @ApiOperation(value = "删除 个人类型考核总计信息")
    @ApiImplicitParam(name = "id", value = "个人类型考核总计信息id", dataType = "Long", example = "1")
    public ResultVo delete(@PathVariable Long id) {
        judicialTargetTypeSumCheckService.delete(id);
        return ResultVoUtil.success();
    }

    @GetMapping("/scoreChartRanking")
    @ApiOperation(value = "查询图表 个人类型考核总计信息")
    public ResultVo scoreChartRanking(JudicialTargetTypeSumCheckRankReqVo judicialTargetTypeSumCheckRankReqVo) {
        List<JudicialTargetTypeSumCheckVo> judicialTargetTypeSumCheckVos = judicialTargetTypeSumCheckService.scoreChartRanking(judicialTargetTypeSumCheckRankReqVo);
        return ResultVoUtil.success(judicialTargetTypeSumCheckVos);
    }

    @GetMapping("/scoreChartDepartmentRanking")
    @ApiOperation(value = "查询图表 部门人员类型考核总计信息")
    public ResultVo scoreChartDepartmentRanking(JudicialTargetTypeSumCheckRankReqVo judicialTargetTypeSumCheckRankReqVo) {
        List<JudicialDepartmentSumScoreCheckVo> judicialDepartmentSumScoreCheckVos = judicialTargetTypeSumCheckService.scoreChartDepartmentRanking(judicialTargetTypeSumCheckRankReqVo);
        return ResultVoUtil.success(judicialDepartmentSumScoreCheckVos);
    }



}